cmake_minimum_required(VERSION 3.16)

project(PrescriptionChecker VERSION 1.0.0 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 查找Qt6组件
find_package(Qt6 REQUIRED COMPONENTS Core Network WebEngineWidgets WebChannel)

# 显示Qt6找到的信息
message(STATUS "Qt6_DIR: ${Qt6_DIR}")
message(STATUS "Qt6_FOUND: ${Qt6_FOUND}")

# 启用Qt的MOC
set(CMAKE_AUTOMOC ON)

# 创建动态库
add_library(PrescriptionChecker SHARED
    src/prescriptionchecker.cpp
    src/prescriptionchecker.h
    src/prescriptionchecker_export.cpp
    src/prescriptionchecker_export.h
)

# 设置预处理器定义
target_compile_definitions(PrescriptionChecker PRIVATE PRESCRIPTIONCHECKER_LIBRARY)

# 设置Qt6模块
target_link_libraries(PrescriptionChecker
    Qt6::Core
    Qt6::Network
    Qt6::WebEngineWidgets
    Qt6::WebChannel
)

# 设置包含目录
target_include_directories(PrescriptionChecker PUBLIC
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
    $<INSTALL_INTERFACE:include>
)

# 设置输出目录
set_target_properties(PrescriptionChecker PROPERTIES
    RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
    LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
    ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
)

# 创建示例可执行文件
add_executable(PrescriptionCheckerExample
    main.cpp
)

# 链接示例程序
target_link_libraries(PrescriptionCheckerExample
    PrescriptionChecker
    Qt6::Core
    Qt6::Widgets
    Qt6::WebEngineWidgets
    Qt6::WebChannel
)

# 设置示例程序输出目录
set_target_properties(PrescriptionCheckerExample PROPERTIES
    RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)

# 安装规则
install(TARGETS PrescriptionChecker PrescriptionCheckerExample
    EXPORT PrescriptionCheckerTargets
    LIBRARY DESTINATION lib
    ARCHIVE DESTINATION lib
    RUNTIME DESTINATION bin
    INCLUDES DESTINATION include
)

install(FILES 
    src/prescriptionchecker.h
    src/prescriptionchecker_export.h
    DESTINATION include
)
